package com.bestillet.kyllingogco;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuArrayAdapter extends ArrayAdapter<Menu> {
	private ArrayList<Menu> menu;
	
	private Activity context;
	
	public MenuArrayAdapter(Context context, ArrayList<Menu> menu) {
		super(context, R.layout.menu_item, menu);
		this.context = (Activity) context;
		this.menu = menu;
	}

	static class ViewHolder {
		protected ImageView image;
		protected TextView name;
		protected TextView price;
		protected TextView description;
		protected TextView obs;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
	 
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.menu_item, parent, false);
			final ViewHolder viewHolder = new ViewHolder();
			
			viewHolder.name = (TextView) view.findViewById(R.id.lblName);
			viewHolder.price = (TextView) view.findViewById(R.id.lblPrice);
			viewHolder.description = (TextView) view.findViewById(R.id.lblDescription);
			viewHolder.obs = (TextView) view.findViewById(R.id.lblObs);
			viewHolder.image = (ImageView) view.findViewById(R.id.imgImage);
			view.setTag(viewHolder);
		} else {
			view = (View) convertView;
		}
		
		Menu m = menu.get(position);
		ViewHolder holder = (ViewHolder) view.getTag();
		holder.image.setImageBitmap(m.getImage());
		holder.name.setText(Html.fromHtml(m.getName().replace("\\n", "<br>")));
		holder.price.setText("Pris " + m.getPrice() + ",-");
		holder.description.setText(Html.fromHtml(m.getDescription().replace("\\n", "<br>")));
		holder.obs.setText(Html.fromHtml(m.getObs().replace("\\n", "<br>")));
		return view;
	}
}